

function isValidName(form) {
    var name = form["name"].value;
    if(name == "" || name == null){
            return false;
    } 
    return true;
}

function isValidSurname(form) {
    var from = form["surname"].value;
    if(from == "" || from == null){
            return false;
    } 
    return true;
}

function isValidState(form) {
    for (var i = 0; i < document.getElementsByName('role').length; i++) {
        if (document.getElementsByName('role')[i].checked) {
            return true;
        }

    }
    return false;
}

function isValidLogin(form) {
    var cost = form["login"].value;
    if(cost == "" || cost == null){
            return false;
    } 
    return true;
}

function isValidPassword(form) {
    var cost = form["password"].value;
    if(cost == "" || cost == null){
            return false;
    } 
    return true;
}

function validate()
{
	isValid = new Boolean(true);
	var form = document.form;
	
	if(!isValidName(form)){
	    isValid = false;
	    document.getElementById("errorName").style.display='block';
	} else {
        document.getElementById("errorName").style.display='none';
    }
	
	if(!isValidSurname(form)){
	    isValid = false;
	    document.getElementById("errorSurname").style.display='block';
	} else {
        document.getElementById("errorSurname").style.display='none';
    }
	
	if(!isValidState(form)){
	    isValid = false;
	    document.getElementById("errorRole").style.display='block';
	} else {
        document.getElementById("errorRole").style.display='none';
    }
	
	if(!isValidLogin(form)){
	    isValid = false;
	    document.getElementById("errorLogin").style.display='block';
	} else {
        document.getElementById("errorLogin").style.display='none';
    }
	
	if(!isValidPassword(form)){
	    isValid = false;
	    document.getElementById("errorPassword").style.display='block';
	} else {
        document.getElementById("errorPassword").style.display='none';
    }
	
	if(isValid == false){
	    event.preventDefault();
	    return false;
	}
	else
	{
		form.submit;
	}
}
